﻿using BLL;
using DBUtility;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace APPMsgPush
{
    /// <summary>
    /// AddMessage 的摘要说明
    /// </summary>
    public class AddMessage : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string appName = HttpContext.Current.Request.Params["AppName"];//項目名稱
            string message = HttpContext.Current.Request.Params["Message"];//要推送的内容
            string data = HttpContext.Current.Request.Params["data"];
            string aztokenList = HttpContext.Current.Request.Params["aztokenList"].Replace("\r\n","");//android设备集合
            string iostokenList = HttpContext.Current.Request.Params["iostokenList"];//ios设备集合
            //string[] str = aztokenList.Split(',');
            bool bo = true;
            App model = AppBLL.CurrBll.GetmodelByAppName(out bo, appName);
            if (model == null)
            {
                JsonHelper.Fail("没有对应的项目！");
            }

            int Id = PendingpushmessageBLL.CurrBll.AddList(model.Id, message, data, aztokenList, iostokenList);
            if (Id > 0)
            {
                JsonHelper.Success();
            }
            else
            {
                JsonHelper.Fail("添加失敗！");
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}